﻿using System;
using System.Linq;
using XEvolve.Core.Runtime.Attributes;
using System.Reflection;
using System.Collections.Generic;

namespace XEvolve.Core.Runtime.Internal
{
    internal static class TypeExtension
    {
        public static IEnumerable<Type> GetPlugins(this Assembly assembly)
        {
            return assembly.GetExportedTypes().Where(type => type.IsPluginType());
        }

        public static bool IsPluginType(this Type type)
        {
            return !type.IsAbstract && type.IsSubclassOf(typeof(Plugin)) && type.IsDefined(typeof (PluginIdAttribute), false);
        }
    }
}